<?php

class {$className} extends f_core_Action
{ldelim}
	public function execute()
	{ldelim}
		$formProvider = f_form_Provider::getInstance();
		
		$formProvider->setDocumentName("{$formName}")
		             ->setModuleName("{$moduleName}")
		             ->setFormName("Form{$documentName}");
		
		$this->setModel($formProvider->getParams());
		
		if($formProvider->isSubmitted())
		{ldelim}
			if($formProvider->isValid())
			{ldelim}
				// Your code here
			{rdelim}
			else
			{ldelim}
				$this->addToModel("errors", $formProvider->getErrors());
			{rdelim}
		{rdelim}
{if isset($specialFields)} 			
		// Retrieve special fields
		$specialFields = $this->specialFields();
		if($specialFields != null)
		{ldelim}
			$this->addToModel("relatedDocs", $specialFields);
		{rdelim}
{/if}
		$this->setView('success');
	{rdelim}	
	
	public function validate()
	{ldelim}
		return true;
	{rdelim}
	
	public function errorHandler()
	{ldelim}
		$this->setView('error');
	{rdelim}
	
{if isset($specialFields)} 	
	private function specialFields()
	{ldelim}
		// Retrieve field of type "document"
		$specialFields = unserialize('{$specialFields}');

		if(count($specialFields) > 0)
		{ldelim}
			$documentProvider = f_document_Provider::getInstance();
			$relatedDocs = array();
			
			// For each special fields
			foreach($specialFields as $currentDoc)
			{ldelim}
				// Case of document type
				if(preg_match("#^modules_(.*)\/(.*)$#i", $currentDoc['from']))
				{ldelim}
					// Retrieve columns data from currentDoc to populate the selectbox fields
					$columns = array("document_uid", $currentDoc["foreignField"]);
					$relatedDocs[$currentDoc['name']] = $documentProvider->loadDocuments($currentDoc['from'])->retrieveColumnValues($columns);
				{rdelim}
				else
				{ldelim}
					// Action type
					ob_start();
					$this->launchActionByClassName($currentDoc['from']);
					$out = ob_get_contents();
					ob_end_clean();
				
					$relatedDocs[$currentDoc['name']] = unserialize($out);
				{rdelim}
			{rdelim}
			return $relatedDocs;
		{rdelim}
		return null;
	{rdelim}
{/if}
{rdelim}	